package com.ocom.company.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.human.EntityBizLeaveApply;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDaoBizLeaveApply extends BaseMapper<EntityBizLeaveApply> {
    @Select({"<script>",
            "select  l.* ,b.activiti_key,b.def_key,b.title \n" +
                    "FROM biz_leave_apply l \n" +
                    "LEFT JOIN biz_apply  b   ON b.business_id=l.id AND b.def_key = #{defKey} \n" +
                    "where" +
                    " <when test=\"ids ==null or ids.size()==0 \" > "+
                    " l.com_id=#{comId} " +
                    " <when test=\"pId!=null and pId > 0\" > "+
                    "and  l.p_id=#{pId} " +
                    " </when> "+
                    " </when> "+
                    " <when test=\"ids !=null and ids.size()>0 \" > "+
                    " l.id in" +
                    "<foreach collection='ids' item='item' open='(' separator=',' close=')'>" +
                    "#{item}" +
                    "</foreach>"+
                    " </when> "+
                    "order by l.create_time desc " +
                    "</script>"})
    List<EntityBizLeaveApply> getList(@Param("defKey") String defKey,
                                      @Param("comId") Long comId,
                                      @Param("pId") Long pId,
                                      @Param("ids") List<Integer> ids
                                      );


    @Select({"<script>",
            "select  l.* ,b.activiti_key,b.def_key,b.title \n" +
                    "FROM biz_leave_apply l \n" +
                    "LEFT JOIN biz_apply  b   ON b.business_id=l.id AND b.def_key like \"leave-apply%\"  \n" +
                    "where" +
                    " l.id =#{id} " +
                    "</script>"})
    EntityBizLeaveApply getInfo(@Param("id") Integer id);

}
